<?php
class ScreensController extends AppController{
    var $name='Screens';
    
    function beforeFilter(){
        if(isset($this->params['user']) && $this->params['user']) {     
            $this->checkUser();   
        }   
    }
    function index(){
        $user=$this->Session->read('User');
        $this->set('screens',$this->Screen->find('all',array('conditions'=>'users_id='.$user['User']['id'])));
    } 
    
    function edit($id=null){
        if(empty($this->data)){
            $this->Screen->id = $id;
            $this->data = $this->Screen->read();
        }else{
            if($this->Screen->save($this->data['Screen'])){
                $this->flash('Your screen has been updated.');
                $this->redirect(array('action'=>'index'));
            }
        }
    }
    function add(){
        if(!empty($this->data)){
            $this->Screen->create();
            if($this->Screen->save($this->data)){
                $this->Session->setFlash(__('Edit complete',null,true));
                $this->redirect(array('controller'=>'screens','action'=>'index'));
            }else{
                $this->Session->setFlash(__('Cannot update',null,true));
                $this->redirect(array('controller'=>'screens','action'=>'index'));
            }   
        }
    } 
    function delete($id){
        $this->Screen->del($id);
        $this->flash('The screen with id: '.$id.' has been deleted.',
        '/screens');
    } 
}
?>
